import getState from "@/api/state";
import ZuirealTimeData from "@/template/realTimeData/realTimeData";
import React from "react"
import { useEffect } from "react";
import { useState } from "react";

const InsModule2 = ({ condition }) => {

    const [loading, setLoading] = useState(true);

    // 累计保费
    const [amtState, setAmtState] = useState({
        title: "累计保费",
        value: 0,
        unit: "万元",
        toFixed:true,
        childrenData: [
            {
                title: "全险种",
                value: 0
            },
            {
                title: "车险",
                value: 0
            },
            {
                title: "意健险",
                value: 0
            },
            {
                title: "财产险",
                value: 0
            },
        ]
    },)
    // 人均保费
    const [avgState, setAvgState] = useState({
        title: "人均保费",
        value: 0,
        unit: "万元",
        toFixed:true,
        childrenData: [
            {
                title: "全险种",
                value: 0
            },
            {
                title: "车险",
                value: 0
            },
            {
                title: "意健险",
                value: 0
            },
            {
                title: "财产险",
                value: 0
            },
        ]
    })
    // 退保客户数
    const [cancelState, setCancelState] = useState({
        title: "退保客户数",
        value: 0,
        unit: "人数",
        childrenData: [
            {
                title: "全险种",
                value: 0
            },
            {
                title: "车险",
                value: 0
            },
            {
                title: "意健险",
                value: 0
            },
            {
                title: "财产险",
                value: 0
            },
        ]
    })
    // 客单量
    const [plynState, setPlyState] = useState({
        title: "客单量",
        value: 0,
        unit: "件数",
        childrenData: [
            {
                title: "全险种",
                value: 0,
            },
            {
                title: "车险",
                value: 0
            },
            {
                title: "意健险",
                value: 0,
            },
            {
                title: "财产险",
                value: 0,
            },
        ]
    })




    useEffect(() => {
        // 累计保费
        getState({
            apiUrl: "/cifgp-core-api/insQuery/monthAndYear",
            condition: { ...condition, cType: "insAmt" },
            state: amtState,
            setState: setAmtState,
            setLoading,
        })
        // // 人均保费
        getState({
            apiUrl: "/cifgp-core-api/insQuery/specialMonthAndYear",
            condition: { ...condition, cType: "insAvgAmt" },
            state: avgState,
            setState: setAvgState,
            setLoading,
        })
        // 退保客户数
        getState({
            apiUrl: "/cifgp-core-api/insQuery/monthAndYear",
            condition: { ...condition, cType: "insCancel" },
            state: cancelState,
            setState: setCancelState,
            setLoading,
        })
        // 获取客单量
        getState({
            apiUrl: "/cifgp-core-api/insQuery/monthAndYear",
            condition: { ...condition, cType: "plyNum" },
            state: plynState,
            setState: setPlyState,
            setLoading,
        })
    }, [condition])
    return (
        <>
            <ZuirealTimeData
                loading={loading}
                style={{ width: "50%" }}
                title="承保信息"
                hideBtn
                hideDownBtn
                transparent
                wrap
                itemStyle={{ width: "50%" }}
                data={[amtState, avgState, cancelState, plynState]}
            />
        </>
    )
}
export default InsModule2;